﻿using System.IO;
using UnityEngine;

namespace StationPriority {
    class StationPatchContext {
        public int StationId { get; private set; }
        public int SupplyPriority { get; set; }

        public StationPatchContext(
            int stationId, 
            int supplyPriority
            ) {
            StationId = stationId;
            SupplyPriority = supplyPriority;
        }

        public void Export(TextWriter writer) {
            writer.WriteLine($"{StationId},{SupplyPriority}");
            //Debug.Log($"StationPriority: 保存数据<{StationId},{SupplyPriority}>");
        }

        public static StationPatchContext Import(TextReader reader) {
            string line = reader.ReadLine();
            if (line == null) {
                return null;
            }

            string[] args = line.Split(',');
            if (args.Length != 2) {
                return null;
            }

            int stationId = int.Parse(args[0]);
            int supplyPriority = int.Parse(args[1]);

            //Debug.Log($"StationPriority: 加载数据<{stationId},{supplyPriority}>");
            return new StationPatchContext(stationId, supplyPriority);
        }
    }
}
